#coding：utf-8
from django.db import models
from django.utils import timezone
import datetime

# Create your models here.
from django.utils.encoding import python_2_unicode_compatible

@python_2_unicode_compatible # only if you need to support python 2
class Question(models.Model):
    question_text = models.CharField(max_length=200)
    pub_date= models.DateTimeField('date published')
    def __str__(self):
        return self.question_text

    def was_published_recently(self):
        return self.pub_date > timezone.now() - datetime.timedelta(days=1)

    was_published_recently.admin_order_field = 'pub_date'
    was_published_recently.boolean = True
    was_published_recently.short_description = 'Published recently?'

@python_2_unicode_compatible
class Choice(models.Model):
    question=models.ForeignKey(Question, on_delete=models.CASCADE)
    choice_text = models.CharField(max_length=200)
    votes = models.IntegerField(default=0)
    def __str__(self):
        return self.choice_text

@python_2_unicode_compatible
class Flight(models.Model):
    id = models.AutoField(primary_key=True)
    flight_no=models.CharField(max_length=10,unique=True)
    airport_from=models.CharField(max_length=4)
    airport_to=models.CharField(max_length=4)
    airline = models.CharField(max_length=100)
    expected_takeoff_time = models.DateTimeField('Expected TakeOff Time')
    actual_takeoff_time = models.DateTimeField("Actual TakeOff Time")
    expected_arrival_time = models.DateTimeField('Expected Landing Time')
    actual_arrival_time = models.DateTimeField("Actual Landing Time")

    def isDelyTakeoffFlight(self):
        return self.actual_take_time > self.expected_takeoff_time

    def isDelayLandingFlight(self):
        return self.actual_arriva_time > self.expected_arrival_time

    def __str__(self):
        return "Flight No";

@python_2_unicode_compatible
class FlightGroundGuardJob(models.Model):
    Type_Of_Job=(
        (u'Dinner',u'PrePareDinner'),
        (u'Clean',u'AircraftClean'),
        (u"GroundGuard",u'Ground Guard'),
    )

    Type_Of_Department=(
        (u"FoodSupply",u'Aircraft Food Service'),
        (u'procter_and_gamble',u'procter & gamble'),
        (u'GroundService',u'Ground Service'),
    )
    Job_Id = models.IntegerField()
    flight = models.ForeignKey(Flight, on_delete=models.CASCADE)
    department_attach= models.CharField(max_length = 20, choices=Type_Of_Department)
    Job_Type = models.CharField(max_length = 20,choices=Type_Of_Job)
    expect_start_time = models.TimeField("Expect Start WorkingTime ")
    expect_finish_time = models.TimeField("Expected Finishing Time")
    actual_start_time = models.TimeField("Actual Starting Time")
    actual_finish_time = models.TimeField("Actual Finishing Time")
